package com.itheima.controller;

import com.itheima.project.costomannotation.log ;
import com.itheima.project.PageBean;
import com.itheima.project.Result;
import com.itheima.project.classdata.Clazz;
import com.itheima.project.classdata.ClazzQueryParam;
import com.itheima.filter.service.inter.ClazzService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClassController {
    /**
     * 控制层接收业务请求，接收请求数据，如果数据较多可以创建一个类来接收这些数据
     */
    @Resource
    private ClazzService clazzService;


    @GetMapping
    public Result page(ClazzQueryParam eqp) {
        PageBean page = clazzService.page(eqp);

        return Result.success(page);
    }
    @log
    @DeleteMapping("/{id}")
    public Result deleteClass(@PathVariable Integer id){

        clazzService.deleteClass(id);
        return Result.success();
    }
    @log
    @PostMapping
    public Result addClass(@RequestBody Clazz clazz){
        log.info("接收到信息"+clazz.toString());
        clazzService.addClass(clazz);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result queryClassById(@PathVariable Integer id){
        Clazz clazz = clazzService.queryClassById(id);
        return Result.success(clazz);
    }

    @log
    @PutMapping
    public Result modifyClass(@RequestBody Clazz clazz){
        System.out.println("修改部门名称"+clazz);
      clazzService.modifyClass(clazz);
        return Result.success();
    }

    @GetMapping("list")
    public Result queryAllClass(){
        log.info("所有班级查询");
        List list = clazzService.queryAllClass();
        return Result.success(list);
    }
}
